package com.gaohe.post.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.post.domain.FmMessage;
import com.gaohe.post.service.IFmMessageService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 系统消息Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/message")
public class FmMessageController extends BaseController
{
    @Autowired
    private IFmMessageService fmMessageService;

    /**
     * 查询系统消息列表
     */
    @RequiresPermissions("post:message:list")
    @GetMapping("/list")
    public TableDataInfo list(FmMessage fmMessage)
    {
        startPage();
        List<FmMessage> list = fmMessageService.selectFmMessageList(fmMessage);
        return getDataTable(list);
    }

    /**
     * 导出系统消息列表
     */
    @RequiresPermissions("post:message:export")
    @Log(title = "系统消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmMessage fmMessage)
    {
        List<FmMessage> list = fmMessageService.selectFmMessageList(fmMessage);
        ExcelUtil<FmMessage> util = new ExcelUtil<FmMessage>(FmMessage.class);
        util.exportExcel(response, list, "系统消息数据");
    }

    /**
     * 获取系统消息详细信息
     */
    @RequiresPermissions("post:message:query")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(fmMessageService.selectFmMessageByMessageId(messageId));
    }

    /**
     * 新增系统消息
     */
    @RequiresPermissions("post:message:add")
    @Log(title = "系统消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmMessage fmMessage)
    {
        return toAjax(fmMessageService.insertFmMessage(fmMessage));
    }

    /**
     * 修改系统消息
     */
    @RequiresPermissions("post:message:edit")
    @Log(title = "系统消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmMessage fmMessage)
    {
        return toAjax(fmMessageService.updateFmMessage(fmMessage));
    }

    /**
     * 删除系统消息
     */
    @RequiresPermissions("post:message:remove")
    @Log(title = "系统消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(fmMessageService.deleteFmMessageByMessageIds(messageIds));
    }
}
